package com.cbry.easyddl.util;

import com.cbry.easyddl.enums.MySqlTypeEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @Classname JavaToMySQLTypeConverter
 * @Description
 * @Date 2024/4/26 17:34
 * @Created by liaoxg
 */
public class JavaToMySQLTypeConverter {
    private static Map<String, String> typeMap = new HashMap<>();

    static {
        typeMap.put("int", "int");
        typeMap.put("long", "bigint");
        typeMap.put("float", "float");
        typeMap.put("double", "double");
        typeMap.put("boolean", "boolean");
        typeMap.put("char", "char");
        typeMap.put("string", "varchar");
        typeMap.put("byte", "tinyint");
        typeMap.put("short", "smallint");
        typeMap.put("Date", "date");
        typeMap.put("time", "time");
        typeMap.put("timestamp", "timestamp");
        typeMap.put("bigDecimal", "decimal(10,2)");
        typeMap.put("blob", "blob");
        typeMap.put("clob", "text");
        typeMap.put("byte[]", "blob");
        // 添加更多数据类型的映射关系
        typeMap.put("java.lang.Integer", "INT");
        typeMap.put("java.lang.Long", "BIGINT");
        typeMap.put("java.lang.Boolean", "TINYINT");
        typeMap.put("java.lang.Float", "FLOAT");
        typeMap.put("java.lang.Double", "DOUBLE");
        typeMap.put("java.math.BigDecimal", "DECIMAL(10,2)");
        typeMap.put("java.lang.Character", "CHAR");
        typeMap.put("java.lang.String", "VARCHAR");
        typeMap.put("java.sql.Date", "DATE");
        typeMap.put("java.sql.Time", "TIME");
        typeMap.put("java.time.LocalDateTime", "datetime");
        typeMap.put("java.sql.Timestamp", "TIMESTAMP");
    }

    public static String convertJavaToMySQLType(String javaType) {
        // return typeMap.getOrDefault(javaType, typeMap.getOrDefault(javaType , typeMap.get("string")) + );
        // Map<String, String> alarmTypeMap = Stream.of(MySqlTypeEnum.values())
        //         .collect(Collectors.toMap(MySqlTypeEnum::getJavaType, MySqlTypeEnum::getMysqlType));

        //输出控制台
        //colorMap.forEach((key, value) -> System.out.println(key + " -> " + value));
        return MySqlTypeEnum.getMysqlTypeByJavaType(javaType,true);

    }

    public static void main(String[] args) {
        System.out.println(convertJavaToMySQLType("int")); // 输出：INT
        System.out.println(convertJavaToMySQLType("String")); // 输出：VARCHAR
        System.out.println(convertJavaToMySQLType("dawdw")); // 输出：VARCHAR
        // 添加更多测试用例

    }
}
